package com.js.purs.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.js.purs.mapper.PurEvaFileMapper;
import com.js.purs.domain.PurEvaFile;
import com.js.purs.service.IPurEvaFileService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 招标附件Service业务层处理
 * 
 * @author lzq
 * @date 20240708
 */
@Service
public class PurEvaFileServiceImpl implements IPurEvaFileService 
{
    @Autowired
    private PurEvaFileMapper purEvaFileMapper;

    /**
     * 查询招标附件
     * 
     * @param evaCode 招标附件主键
     * @return 招标附件
     */
    @Override
    public PurEvaFile selectPurEvaFileByEvaCode(String evaCode)
    {
        return purEvaFileMapper.selectPurEvaFileByEvaCode(evaCode);
    }

    /**
     * 查询招标附件列表
     * 
     * @param purEvaFile 招标附件
     * @return 招标附件
     */
    @Override
    public List<PurEvaFile> selectPurEvaFileList(PurEvaFile purEvaFile)
    {
        return purEvaFileMapper.selectPurEvaFileList(purEvaFile);
    }

    /**
     * 新增招标附件
     * 
     * @param purEvaFile 招标附件
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertPurEvaFile(PurEvaFile purEvaFile)
    {
        int index =0;
        List<PurEvaFile> evaFiles = purEvaFileMapper.selectPurEvaFileList(purEvaFile);
        for (PurEvaFile file : evaFiles) {
            index = purEvaFileMapper.deletePurEvaFileByBindCode(file.getBindCode());
        }

        purEvaFile.setCreateTime(DateUtils.getNowDate());
        index = purEvaFileMapper.insertPurEvaFile(purEvaFile);
        return index;
    }

    /**
     * 修改招标附件
     * 
     * @param purEvaFile 招标附件
     * @return 结果
     */
    @Override
    public int updatePurEvaFile(PurEvaFile purEvaFile)
    {
        return purEvaFileMapper.updatePurEvaFile(purEvaFile);
    }

    /**
     * 批量删除招标附件
     * 
     * @param evaCodes 需要删除的招标附件主键
     * @return 结果
     */
    @Override
    public int deletePurEvaFileByEvaCodes(String[] evaCodes)
    {
        return purEvaFileMapper.deletePurEvaFileByEvaCodes(evaCodes);
    }

    /**
     * 删除招标附件信息
     * 
     * @param binCode 招标附件主键
     * @return 结果
     */
    @Override
    public int deletePurEvaFileByBindCode(String binCode)
    {
        return purEvaFileMapper.deletePurEvaFileByBindCode(binCode);
    }
}
